﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Media.Imaging;
using System.IO;

namespace ListEffect
{
    public partial class MainPage : UserControl
    {
        List<FrameworkElement> lstImg = new List<FrameworkElement>();

        public MainPage()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(MainPage_Loaded);
        }

        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            //lstImg.Add(new Image() { Source = new BitmapImage(new Uri("01.jpg", UriKind.Relative)), Stretch = Stretch.Fill });
            //lstImg.Add(new Image() { Source = new BitmapImage(new Uri("02.jpg", UriKind.Relative)), Stretch = Stretch.Fill });
            //lstImg.Add(new Image() { Source = new BitmapImage(new Uri("03.jpg", UriKind.Relative)), Stretch = Stretch.Fill });
            //lstImg.Add(new Image() { Source = new BitmapImage(new Uri("04.jpg", UriKind.Relative)), Stretch = Stretch.Fill });
            //lstImg.Add(new Image() { Source = new BitmapImage(new Uri("05.jpg", UriKind.Relative)), Stretch = Stretch.Fill });
            //lstImg.Add(new Image() { Source = new BitmapImage(new Uri("06.jpg", UriKind.Relative)), Stretch = Stretch.Fill });
            //lstImg.Add(new Image() { Source = new BitmapImage(new Uri("01.jpg", UriKind.Relative)), Stretch = Stretch.Fill });
            //lstImg.Add(new Image() { Source = new BitmapImage(new Uri("02.jpg", UriKind.Relative)), Stretch = Stretch.Fill });
            //lstImg.Add(new Image() { Source = new BitmapImage(new Uri("03.jpg", UriKind.Relative)), Stretch = Stretch.Fill });
            //lstImg.Add(new Image() { Source = new BitmapImage(new Uri("04.jpg", UriKind.Relative)), Stretch = Stretch.Fill });
            //lstImg.Add(new Image() { Source = new BitmapImage(new Uri("05.jpg", UriKind.Relative)), Stretch = Stretch.Fill });
            //lstImg.Add(new Image() { Source = new BitmapImage(new Uri("06.jpg", UriKind.Relative)), Stretch = Stretch.Fill });
            //lstImg.Add(new Image() { Source = new BitmapImage(new Uri("01.jpg", UriKind.Relative)), Stretch = Stretch.Fill });
            //lstImg.Add(new Image() { Source = new BitmapImage(new Uri("02.jpg", UriKind.Relative)), Stretch = Stretch.Fill });
            //lstImg.Add(new Image() { Source = new BitmapImage(new Uri("03.jpg", UriKind.Relative)), Stretch = Stretch.Fill });
            //lstImg.Add(new Image() { Source = new BitmapImage(new Uri("04.jpg", UriKind.Relative)), Stretch = Stretch.Fill });
            //lstImg.Add(new Image() { Source = new BitmapImage(new Uri("05.jpg", UriKind.Relative)), Stretch = Stretch.Fill });
            //lstImg.Add(new Image() { Source = new BitmapImage(new Uri("06.jpg", UriKind.Relative)), Stretch = Stretch.Fill });
            //pageTurn1.LstPageContent = lstImg;
        }

        private void TextBox_KeyUp(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
                case Key.Left:
                    pageTurn1.Prev();
                    break;
                case Key.Right:
                    pageTurn1.Next();
                    break;
                default:
                    break;
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog() { Multiselect = true };
            ofd.ShowDialog();
            lstImg.Clear();
            foreach (FileInfo f in ofd.Files)
            {
                BinaryReader br = new BinaryReader(f.OpenRead());
                BitmapImage bi = new BitmapImage();
                byte[] buffer = br.ReadBytes((int)br.BaseStream.Length);
                MemoryStream ms = new MemoryStream(buffer, 0, buffer.Length);
                bi.SetSource(ms);
                lstImg.Add(new Image() { Source = bi, Stretch = Stretch.Fill });                               
            }
            
            pageTurn1.LstPageContent = lstImg;
        }
    }
}
